package cn.ehanghai.htz.domain;

import cn.ehanghai.htz.common.utils.DateUtil;
import dk.tbsalling.aismessages.ais.messages.PositionReport;
import lombok.Data;

import javax.persistence.Column;
import java.time.Instant;
import java.util.Date;

/**
 * @Author: xumf
 * @Date: 2019/7/5 10:48
 */
@Data
public class Position {

    private Integer id;
    private Integer mmsi;
    private Float lat;
    private Float lon;
    @Column(name = "rate_of_turn")
    private Integer rateOfTurn;
    @Column(name = "speed_over_ground")
    private Float speedOverGround;
    @Column(name = "course_over_ground")
    private Float courseOverGround;
    @Column(name = "create_date")
    private String createDate;
    @Column(name = "update_date")
    private String updateDate;
    private String name;

    public Position() {
    }

    public Position(PositionReport msg) {
        this.name="虚拟船舶";
        this.mmsi = msg.getSourceMmsi().getMMSI();
        this.lat = msg.getLatitude();
        this.lon = msg.getLongitude();
        this.rateOfTurn = msg.getRateOfTurn();
        this.speedOverGround = msg.getSpeedOverGround();
        this.courseOverGround=msg.getCourseOverGround();
        this.createDate=(DateUtil.getCurrentDateLong());
        this.updateDate=updateTime(msg.getMetadata().getReceived());
    }

    private String updateTime(Instant times){
        Date temp=Date.from(times);
        return DateUtil.dateToString(temp);
    }
}
